using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Ltf.Diffs
{
	public class ScintillaDiffDocLoader
	{

		public static Dictionary<long, string> MarkerNames = new Dictionary<long, string>();
		public static Dictionary<long, string> MarkerOutputNames = new Dictionary<long, string>();
		static ScintillaDiffDocLoader()
		{
			MarkerNames.Add(Bits(2, 22), "Text after change");
			MarkerNames.Add(Bits(3, 23), "Text before change");
			MarkerNames.Add(Bits(4, 24), "Added text");
			MarkerNames.Add(Bits(5, 25), "Deleted text");
			MarkerNames.Add(Bits(6, 26), "Non-checked local in changes");
			MarkerNames.Add(Bits(16, 21), "Deleted text, same as their change");
			MarkerNames.Add(Bits(15, 20), "Mergeable deleted text");
			MarkerNames.Add(Bits(14, 19), "Their deletes conflicts with your change");
			MarkerNames.Add(Bits(13, 18), "Added text, same as their change");
			MarkerNames.Add(Bits(12, 17), "Mergeable added text");
			MarkerNames.Add(Bits(11, 1), "Their added text conflicts with your change");
			MarkerNames.Add(Bits(10, 30), "Thier change is the same as your change");
			MarkerNames.Add(Bits(9, 29), "Mergeable changed text");
			MarkerNames.Add(Bits(8, 28), "Their changed text conflicts with your change");

			MarkerOutputNames.Add(2, "Thier change text");
			MarkerOutputNames.Add(3, "Your change text");
			MarkerOutputNames.Add(8, "Resolved Text");
			MarkerOutputNames.Add(27, "No matching text");
			MarkerOutputNames.Add(4, "Text merged from theirs");
			MarkerOutputNames.Add(5, "Deletion merged below");
			MarkerOutputNames.Add(6, "Deletion merged above");
			MarkerOutputNames.Add(10, "Conflict resolved below");
			MarkerOutputNames.Add(11, "Conflict resolved above");
			MarkerOutputNames.Add(12, "Original text, merge undone below");
			MarkerOutputNames.Add(13, "Original text, merge undone above");
			MarkerOutputNames.Add(14, "Orginal text - merge undone");
			MarkerOutputNames.Add(9, "Mergeable changed text");
		}


		public static void ShowDiffDocument(ScintillaExtra numbers, ScintillaExtra text, DiffDocument doc)
		{
			text.Text = doc.GetDocumentText();
			numbers.Text = doc.GetLineNumbersText();
			AddMarkers(numbers, text, doc);
		}

		public static void ShowMergedOutput(ScintillaExtra text, DiffDocument doc)
		{
			text.Text = doc.GetDocumentText();
			AddOutputMarkers(text, doc);
		}



		public static void ShowBlameDocument(ScintillaExtra numbers, ScintillaExtra text, DiffDocument doc)
		{
			text.Text = doc.GetChangeInfo();
			AddMarkers(numbers, text, doc);
		}

		private static void AddMarkers(ScintillaExtra numbers, ScintillaExtra text, DiffDocument doc)
		{
			string rightGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #0088FF\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAABAAAAAAA\",\"AAAAAAAABBAAAAAA\",\"AAAAAAAABCBAAAAA\",\"AAAAAAAABCCBAAAA\",\"AAAAAAAABCCCBAAA\",\"AAAAAAAABCCCCBAA\",\"AAAAAAAABCCCCCBA\",\"AAAAAAAABCCCCBAA\",\"AAAAAAAABCCCBAAA\",\"AAAAAAAABCCBAAAA\",\"AAAAAAAABCBAAAAA\",\"AAAAAAAABBAAAAAA\",\"AAAAAAAABAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";

			string leftGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #0088FF\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAABAAA\",\"AAAAAAAAAAABBAAA\",\"AAAAAAAAAABCBAAA\",\"AAAAAAAAABCCBAAA\",\"AAAAAAAABCCCBAAA\",\"AAAAAAABCCCCBAAA\",\"AAAAAABCCCCCBAAA\",\"AAAAAAABCCCCBAAA\",\"AAAAAAAABCCCBAAA\",\"AAAAAAAAABCCBAAA\",\"AAAAAAAAAABCBAAA\",\"AAAAAAAAAAABBAAA\",\"AAAAAAAAAAAABAAA\",\"AAAAAAAAAAAAAAAA\"};";


			int sectionBreakStyle = 1;
			text.StyleSetFore(sectionBreakStyle, 0x8080ff);

			int conflictStyle = 2;
			text.StyleSetFore(conflictStyle, 0x40ffff);
			text.StyleSetFont(conflictStyle, "Courier New");
			text.StyleSetBold(conflictStyle, true);

			int deletedStyle = 3;
			text.StyleSetFore(deletedStyle, 0x707070);
			text.StyleSetFont(deletedStyle, "Courier New");
			text.StyleSetBold(deletedStyle, false);


			text.MarkerDefine(2, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(2, rightGlyph);
			text.MarkerDefine(22, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(2, 0xff8080);
			text.MarkerSetBackgroundColor(22, 0xff8080);
			text.MarkerDefine(3, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(3, leftGlyph);
			text.MarkerDefine(23, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(3, 0xffc0c0);
			text.MarkerSetBackgroundColor(23, 0xffc0c0);
			text.MarkerDefine(4, Scintilla.Enums.MarkerSymbol.Plus);
			text.MarkerDefine(24, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(4, 0xa0ffa0);
			text.MarkerSetBackgroundColor(24, 0xa0ffa0);
			text.MarkerDefine(5, Scintilla.Enums.MarkerSymbol.Minus);
			text.MarkerDefine(25, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(5, 0xe0b0ff);
			text.MarkerSetBackgroundColor(25, 0xe0b0ff);
			text.MarkerDefine(6, Scintilla.Enums.MarkerSymbol.Circle);
			text.MarkerDefine(26, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(6, 0xe080ff);
			text.MarkerSetBackgroundColor(26, 0xe080ff);
			text.MarkerDefine(27, Scintilla.Enums.MarkerSymbol.Empty);
			text.MarkerSetForegroundColor(27, 0xff40ff);

			// change conflict, change mergable, change same.
			text.MarkerDefine(8, Scintilla.Enums.MarkerSymbol.BoxPlus);
			text.MarkerDefine(28, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(8, 0xff0060);
			text.MarkerSetBackgroundColor(28, 0xff0060);
			text.MarkerDefine(9, Scintilla.Enums.MarkerSymbol.CirclePlus);
			text.MarkerDefine(29, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(9, 0xff4040);
			text.MarkerSetBackgroundColor(29, 0xff4040);
			text.MarkerDefine(10, Scintilla.Enums.MarkerSymbol.Circle);
			text.MarkerDefine(30, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(10, 0xffb060);
			text.MarkerSetBackgroundColor(30, 0xffb060);

			// add conflict, change mergable, change same.
			text.MarkerDefine(11, Scintilla.Enums.MarkerSymbol.BoxPlus);
			text.MarkerDefine(1, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(11, 0x30a000);
			text.MarkerSetBackgroundColor(1, 0x30a000);
			text.MarkerDefine(12, Scintilla.Enums.MarkerSymbol.CirclePlus);
			text.MarkerDefine(17, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(12, 0x50a060);
			text.MarkerSetBackgroundColor(17, 0x50a060);
			text.MarkerDefine(13, Scintilla.Enums.MarkerSymbol.Circle);
			text.MarkerDefine(18, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(13, 0x80ff80);
			text.MarkerSetBackgroundColor(18, 0x80ff80);

			// delete conflict, change mergable, change same.
			text.MarkerDefine(14, Scintilla.Enums.MarkerSymbol.BoxMinus);
			text.MarkerDefine(19, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(14, 0x0000c0);
			text.MarkerSetBackgroundColor(19, 0x0000cf);
			text.MarkerDefine(15, Scintilla.Enums.MarkerSymbol.CircleMinus);
			text.MarkerDefine(20, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(15, 0x8080ff);
			text.MarkerSetBackgroundColor(20, 0x8080ff);
			text.MarkerDefine(16, Scintilla.Enums.MarkerSymbol.Circle);
			text.MarkerDefine(21, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(16, 0xec0c0ff);
			text.MarkerSetBackgroundColor(21, 0xec0c0ff);

			numbers.MarkerDefine(1, Scintilla.Enums.MarkerSymbol.Background);
			numbers.MarkerSetBackgroundColor(1, 0xf0f0f0);

			int i = 0;
			foreach (Line line in doc.Lines)
			{
				if (numbers != null)
					numbers.MarkerAdd(i, 1);
				if (line.State != LineState.None)
				{
					int marker = 0;
					int bgmarker = 0;
					int pos = text.PositionFromLine(i);
					switch (line.State)
					{
						case LineState.ChangedTo:
							marker = 2;
							bgmarker = 22;
							break;
						case LineState.ChangedFrom:
							marker = 3;
							bgmarker = 23;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, deletedStyle);
							break;
						case LineState.Inserted:
							marker = 4;
							bgmarker = 24;
							break;
						case LineState.Deleted:
							marker = 5;
							bgmarker = 25;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, deletedStyle);
							break;
						case LineState.NotCheckedIn:
							marker = 6;
							bgmarker = 26;
							break;
						case LineState.ConflictChange:
							marker = 8;
							bgmarker = 28;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, conflictStyle);
							break;
						case LineState.MergeableChange:
							marker = 9;
							bgmarker = 29;
							break;
						case LineState.SameChange:
							marker = 10;
							bgmarker = 30;
							break;
						case LineState.ConflictAdd:
							marker = 11;
							bgmarker = 1;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, conflictStyle);
							break;
						case LineState.MergeableAdd:
							marker = 12;
							bgmarker = 17;
							break;
						case LineState.SameAdd:
							marker = 13;
							bgmarker = 18;
							break;
						case LineState.ConflictDelete:
							marker = 14;
							bgmarker = 19;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, conflictStyle);
							break;
						case LineState.MergeableDelete:
							marker = 15;
							bgmarker = 20;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, deletedStyle);
							break;
						case LineState.SameDelete:
							marker = 16;
							bgmarker = 21;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, deletedStyle);
							break;
						case LineState.SectionBreak:
							bgmarker = 27;
							marker = 27;
							text.StartStyling(pos, 0x3f);
							text.SetStyling(line.Text.Length, sectionBreakStyle);
							break;
					}
					text.MarkerAdd(i, marker);
					text.MarkerAdd(i, bgmarker);
				}
				i++;
			}

		}

		private static void AddOutputMarkers(ScintillaExtra text, DiffDocument doc)
		{

			string xpm_data = @"/* XPM */static char * xmp_data[] = {""16 16 4 1"",
                 ""       c None"",
                 "".      c #FF00FF"",
								 ""X      c #FF00FF"",
								 ""Y      c #FFFFFF"",
                 ""                "",
                 ""   ......       "",
                 ""   .XXX.X.      "",
                 ""   .XXX.XX.     "",
                 ""   .XXX.XXX.    "",
                 ""   .XXX.....    "",
                 ""   .XXXXXXX.    "",
                 ""   .XXXXXXY.    "",
                 ""   .YXX.YYX.    "",
                 ""   .XYX.YXX.    "",
                 ""   .X.YY..X.    "",
                 ""   .XXYYXXX.    "",
                 ""   .XYX.YXX.    "",
                 ""   .........    "",
                 ""                "",
                 ""                ""};";



			string upGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #FFBFFF\",\"AAAAAAAABAAAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAABCCCCCBAAAA\",\"AAAABCCCCCCCBAAA\",\"AAABCCCCCCCCCBAA\",\"AAABBBBBBBBBBBAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";
			string downGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #FFBFFF\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAABBBBBBBBBBBAA\",\"AAABCCCCCCCCCBAA\",\"AAAABCCCCCCCBAAA\",\"AAAAABCCCCCBAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAAAABAAAAAAA\"};";

			string mergeGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 4 1\",\"A c None\",\"B c #000000\",\"C c #FFBFFF\",\"D c #C0C0C0\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAABBBAAAAAAAAA\",\"AAAABCBAAABDAAAA\",\"AAAABCBAAABBDAAA\",\"AAAABCBDAABCBDAA\",\"AAAABCCBBBBCCBDA\",\"AAAADBCCCCCCCCBA\",\"AAAAADBBBBBCCBDA\",\"AAAAAAAAAABCBDAA\",\"AAAAAAAAAABBDAAA\",\"AAAAAAAAAABDAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";

			string upUndoneGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #d8ff90\",\"AAAAAAAABAAAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAABCCCCCBAAAA\",\"AAAABCCCCCCCBAAA\",\"AAABCCCCCCCCCBAA\",\"AAABBBBBBBBBBBAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";
			string downUndoneGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #d8ff90\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAABBBBBBBBBBBAA\",\"AAABCCCCCCCCCBAA\",\"AAAABCCCCCCCBAAA\",\"AAAAABCCCCCBAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAAAABAAAAAAA\"};";

			string mergeUndoneGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 4 1\",\"A c None\",\"B c #000000\",\"C c #d8ff90\",\"D c #C0C0C0\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAABBBAAAAAAAAA\",\"AAAABCBAAABDAAAA\",\"AAAABCBAAABBDAAA\",\"AAAABCBDAABCBDAA\",\"AAAABCCBBBBCCBDA\",\"AAAADBCCCCCCCCBA\",\"AAAAADBBBBBCCBDA\",\"AAAAAAAAAABCBDAA\",\"AAAAAAAAAABBDAAA\",\"AAAAAAAAAABDAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";




			string upResolvedGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #e0e0e0\",\"AAAAAAAABAAAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAABCCCCCBAAAA\",\"AAAABCCCCCCCBAAA\",\"AAABCCCCCCCCCBAA\",\"AAABBBBBBBBBBBAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\"};";
			string downResolvedGlyph = "/* XPM */static char * xmp_data[] = {\"16 16 3 1\",\"A c None\",\"B c #000000\",\"C c #e0e0e0\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAAAAAAAAAAAAAAA\",\"AAABBBBBBBBBBBAA\",\"AAABCCCCCCCCCBAA\",\"AAAABCCCCCCCBAAA\",\"AAAAABCCCCCBAAAA\",\"AAAAAABCCCBAAAAA\",\"AAAAAAABCBAAAAAA\",\"AAAAAAAABAAAAAAA\"};";

			//			string m = ScintillaXpm.XpmConverter.ConvertToXPM(new Bitmap("c:\\n.bmp"));

			int sectionBreakStyle = 1;
			text.StyleSetFore(sectionBreakStyle, 0x8080ff);

			int conflictStyle = 2;
			text.StyleSetFore(conflictStyle, 0x40ffff);
			text.StyleSetFont(conflictStyle, "Courier New");
			text.StyleSetBold(conflictStyle, true);

			int deletedStyle = 3;
			text.StyleSetFore(deletedStyle, 0x707070);
			text.StyleSetFont(deletedStyle, "Courier New");
			text.StyleSetBold(deletedStyle, false);

			// theirs


			text.MarkerDefine(2, Scintilla.Enums.MarkerSymbol.Circle);
			//			text.MarkerDefinePixmap(2, upGlyph);
			text.MarkerDefine(22, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(2, 0x005bc9);
			text.MarkerSetBackgroundColor(22, 0x005bc9);

			// yours
			text.MarkerDefine(3, Scintilla.Enums.MarkerSymbol.RoundRectangle);
			text.MarkerDefine(23, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(3, 0x900090);
			text.MarkerSetBackgroundColor(23, 0x900090);

			// resolved
			text.MarkerDefine(8, Scintilla.Enums.MarkerSymbol.RoundRectangle);
			text.MarkerDefine(28, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(8, 0xd0d0d0);
			text.MarkerSetBackgroundColor(28, 0xd0d0d0);


			// no text
			text.MarkerDefine(27, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(27, 0x6060ff);

			// merged text
			text.MarkerDefine(4, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(4, mergeGlyph);
			text.MarkerDefine(24, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(4, 0xf8d8f8);
			text.MarkerSetBackgroundColor(24, 0xffd8f2);

			// text removed below
			text.MarkerDefine(5, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(5, downGlyph);
			// text removed above
			text.MarkerDefine(6, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(6, upGlyph);
			// text resolved below
			text.MarkerDefine(10, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(10, downResolvedGlyph);
			// text resolved above
			text.MarkerDefine(11, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(11, upResolvedGlyph);
			//		text.MarkerSetBackgroundColor(25, 0x6060ff);
			// text undone below
			text.MarkerDefine(12, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(12, downUndoneGlyph);
			// text undone above
			text.MarkerDefine(13, Scintilla.Enums.MarkerSymbol.PixMap);
			text.MarkerDefinePixmap(13, upUndoneGlyph);
			text.MarkerDefine(15, Scintilla.Enums.MarkerSymbol.Circle);
			text.MarkerDefine(14, Scintilla.Enums.MarkerSymbol.Background);
			text.MarkerSetBackgroundColor(14, 0xABEFFF);
			int i = 0;
			foreach (Line line in doc.Lines)
			{
				if (line.State != LineState.None || line.StateAbove!=LineState.None || line.StateBelow!=LineState.None)
					MarkOutputLine(text, line, i);
				i++;
			}
		}

		public static void MarkOutputLine(ScintillaExtra text, Line line, int i)
		{
			int conflictStyle = 2;
			int marker = 0;
			int bgmarker = 0;
			int pos = text.PositionFromLine(i);
			switch (line.State)
			{
				case LineState.MergeTheirs:
					marker = 2;
					bgmarker = 22;
					text.StartStyling(pos, 0x3f);
					text.SetStyling(line.Text.Length, conflictStyle);
					break;
				case LineState.MergeYours:
					marker = 3;
					bgmarker = 23;
					text.StartStyling(pos, 0x3f);
					text.SetStyling(line.Text.Length, conflictStyle);
					break;
				case LineState.MergeNoLinesTheirs:
					marker = 2;
					bgmarker = 27;
					text.StartStyling(pos, 0x3f);
					text.SetStyling(line.Text.Length, conflictStyle);
					break;
				case LineState.MergeNoLinesYours:
					marker = 3;
					bgmarker = 27;
					text.StartStyling(pos, 0x3f);
					text.SetStyling(line.Text.Length, conflictStyle);
					break;
				case LineState.Resolved:
					marker = 8;
					bgmarker = 28;
					break;
				case LineState.MergedOkay:
					marker = 4;
					bgmarker = 24;
					break;
				case LineState.MergeUndone:
					marker = 15;
					bgmarker = 14;
					break;
			}
			switch (line.StateBelow)
			{
				case LineState.MergedOkay:
					bgmarker = 5;
					break;
				case LineState.Resolved:
					bgmarker = 10;
					break;
				case LineState.MergeUndone:
					bgmarker = 12;
					break;
			}
			switch (line.StateAbove)
			{
				case LineState.MergedOkay:
					marker = 6;
					break;
				case LineState.Resolved:
					marker = 11;
					break;
				case LineState.MergeUndone:
					marker = 13;
					break;
			}
			if (marker == 0)
				marker = bgmarker;
			if (bgmarker == 0)
				bgmarker = marker;
			text.MarkerAdd(i, marker);
			text.MarkerAdd(i, bgmarker);
		}

		private static long Bits(int first,int second)
		{
			return (long) (Math.Pow(2, (double)first) + Math.Pow(2, (double)second));
		}
	}
}
